
var chap1_y=$('#chap1').offset().top;
var chap2_y=$('#chap2').offset().top;
var chap3_y=$('#chap3').offset().top;
var chap4_y=$('#chap4').offset().top;
var buffer=20;
$(window).scroll(function(event) {
    var winPos = $(window).scrollTop();
    $("#link1").removeClass('scrolling');
    $("#link2").removeClass('scrolling');
    $("#link3").removeClass('scrolling');
    $("#link4").removeClass('scrolling');
    if(winPos>(chap4_y-buffer)){
        $("#link4").addClass('scrolling')
    }else if(winPos>(chap3_y-buffer)){
        $("#link3").addClass('scrolling')
    }else if(winPos>(chap2_y-buffer)){
        $("#link2").addClass('scrolling')
    }else if(winPos>(chap1_y-buffer)){
        $("#link1").addClass('scrolling')
    }
})